 {extend name="v1/layout/base"}
 {block name="content"}
 <div class="layuimini-main">

   <fieldset class="table-search-fieldset xk-search-status" id="xk-search-status">
     <legend>搜索信息</legend>
     <div style="margin: 10px 10px 10px 10px">
       <div class="layui-row layui-col-space15">
         <div class="layui-col-md12">
           <form class="layui-form">
             <div class="layui-card-body layui-form layui-form-pane">
               <div class="layui-row layui-col-space12 layui-form-item">
                 <div class="layui-col-lg6">
                   <label class="layui-form-label">产品名称</label>
                   <div class="layui-input-block">
                     <input type="text" name="keywords" placeholder="产品名称" id="keywords" class="layui-input">
                   </div>
                 </div>
                 <div class="layui-col-lg6">
                   <label class="layui-form-label">所属仓库</label>
                   <div class="layui-input-block">
                     {volist name="store_list" id="vo"}
                     <input type="checkbox" class="layui-input" lay-skin="primary" name="store_id" value="{$vo.store_id}" title="{$vo.store_name}">
                     {/volist}
                   </div>
                 </div>
               </div>
               <div class="layui-row layui-col-space12 layui-form-item">
                 <div class="layui-col-lg6">
                   <label class="layui-form-label">订单状态</label>
                   <div class="layui-input-block">
                     <input type="checkbox" class="layui-input" lay-skin="primary" name="status" value="0" title="未支付">
                     <input type="checkbox" class="layui-input" lay-skin="primary" name="status" value="1.1" title="待发货">
                     <input type="checkbox" class="layui-input" lay-skin="primary" name="status" value="2.1" title="待自提/配送中">
                     <input type="checkbox" class="layui-input" lay-skin="primary" name="status" value="3.1" title="已完成">
                   </div>
                 </div>
                 <div class="layui-col-lg6">
                   <label class="layui-form-label">售后状态</label>
                   <div class="layui-input-block">
                     <input type="checkbox" class="layui-input" lay-skin="primary" name="goods_status" value="0,1.1,2.1,3.1,4.1,5.34" title="无售后">
                     <input type="checkbox" class="layui-input" lay-skin="primary" name="goods_status" value="5.1,5.2,5.3" title="申请中">
                     <input type="checkbox" class="layui-input" lay-skin="primary" name="goods_status" value="5.12,5.22,5.32" title="驳回">
                     <input type="checkbox" class="layui-input" lay-skin="primary" name="goods_status" value="5.11,5.21,5.24,5.31,5.32" title="处理中">
                     <input type="checkbox" class="layui-input" lay-skin="primary" name="goods_status" value="5.13,5.25" title="完成">
                   </div>
                 </div>
               </div>
               <div class="layui-row layui-col-space12 layui-form-item">
                 <div class="layui-col-lg12">
                   <label class="layui-form-label">付款时间段</label>
                   <div class="layui-input-block">
                     <input type="text" class="layui-input" autocomplete="off" id="pay_time" placeholder="请选择对应的付款时间范围">
                   </div>
                 </div>
               </div>
               <div class="layui-row">
                 <div class="layui-col-xs4">&nbsp;</div>
                 <div class="layui-col-xs5">
                   <button type="reset" class="layui-btn layui-btn-primary  xk-refresh"><i class="fa fa-refresh"></i>&nbsp;重置</button>
                   <button type="button" class="layui-btn layui-btn-normal xk-dosearch">搜索<i class="layui-icon"></i></button>
                   <button type="button" class="layui-btn layui-btn-primary close-search"><i class="layui-icon">&#x1007;</i>关闭</button>
                 </div>
                 <div class="layui-col-xs4">&nbsp;</div>
               </div>
             </div>
           </form>

         </div>
       </div>
     </div>
   </fieldset>

   <script type="text/html" id="toolbar">
     <div class="layui-btn-container">
       <button class="layui-btn layui-btn-black  layui-btn-sm" lay-event="reseve"><i class="layui-icon">&#xe63d;</i></button>
       <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="export"><i class="layui-icon">&#xe67d;</i>导出筛选后的数据</button>
     </div>
   </script>

   <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
   <!-- 图片 如果存在的话 -->
   <script type="text/html" id="picurlshow">
     <img src="{{d.goods_pic?d.goods_pic:'__COMMON__images/no_pic.png'}}" style="width:60px; height:100%" />
   </script>

 </div>
 {/block}
 {block name="myScript"}
 <style media="screen">
   .layui-table-cell {
     height: 60px;
     line-height: 60px;
   }
 </style>
 <script>
   layui.use(['form', 'table', 'laydate'], function() {
     var $ = layui.jquery,
       form = layui.form,
       table = layui.table;
       var laydate = layui.laydate;
       laydate.render({
         elem: '#pay_time',
         range: '~',
         theme: '#1E9FFF',
         type: 'datetime',
       });
     table.render({
       elem: '#currentTableId',
       url: '/{:config("manage.manage_name")}/{:config("manage.version")}/Order/picking',
       toolbar: '#toolbar',
       defaultToolbar: ['filter',{
         title: '搜索',
         layEvent: 'search',
         icon: 'layui-icon-search'
       }],
       height: 'full-50',
       cols: [
         [{
             field: 'goods_pic',
             width: '10%',
             title: '产品图片',
             templet: "#picurlshow",
           },
           {
             field: 'store_name',
             width: '15%',
             title: '所属仓库'
           },
           {
             field: 'goods_name',
             width: '15%',
             title: '产品名称'
           },
           {
             field: 'spec_value',
             width: '15%',
             title: '产品规格'
           },
           {
             field: 'first_buy_count',
             width: '10%',
             title: '首购数量'
           },
           {
             field: 'next_buy_count',
             width: '10%',
             title: '复购数量'
           },
           {
             field: 'all_num',
             width: '10%',
             title: '总计'
           },
           {
             field: 'all_price',
             title: '合计金额'
           }
         ]
       ],
       limits: [100, 150, 200, 250, 500, 1000],
       limit: 100,
       id: 'table_ids',
       page: true,
       skin: 'line'
     });

     // 顶部操作工具
     table.on('toolbar(currentTableFilter)', function(obj) {
       var url = $(this).attr('data-url'),
           id_arr = getCheckValue();
       switch (obj.event) {
         case 'reseve':
           table.reload('table_ids');
           break;
           case 'export':
           var keywords = $("#keywords").val(),
               pay_time = $("#pay_time").val(),
             status = '',
             status_arr = [],
             goods_status = '',
             goods_status_arr = [],
             store_id = '',
             store_id_arr = [];
           $("input[name=status]:checked").each(function() {
             status_arr.push($(this).val());
           });
           status = status_arr.join(',');
           $("input[name=goods_status]:checked").each(function() {
             goods_status_arr.push($(this).val());
           });
           goods_status = goods_status_arr.join(',');
           $("input[name=store_id]:checked").each(function() {
             store_id_arr.push($(this).val());
           });
           store_id = store_id_arr.join(',');
             var url = "/{:config('manage.manage_name')}/{:config('manage.version')}/Order/exportPicking";
             https(url, {
               keywords: keywords,
               status: status,
               store_id: store_id,
               goods_status: goods_status,
               pay_time: pay_time
             }, 'post', true, '正在执行订单数据导出').then(res => {
               if (res.result_code == 200) {
                 var html = '<h1 style="padding: 0 20px;color:red;font-size:18px;margin-bottom:15px;">如果据量大于1万条系统自动分表导出</h1>';
                 res.resultData.forEach(function(value, index) {
                   html += '<h2 style="padding: 0 20px;font-size:16px;">第' + (index + 1) + '个订单文件：<a href="' + value + '">' + '下载' + '</a></h2>';
                 })
                 layer.open({
                   type: 1,
                   skin: 'layui-layer-rim', //加上边框
                   area: ['400px', '200px'], //宽高
                   content: html
                 });
               }
             })
             break;
         case 'search':
           $("#xk-search-status").removeClass('xk-search-status');
           break;
       }
     })
     // 执行搜索
     $(".xk-dosearch").click(function() {
       var keywords = $("#keywords").val(),
           pay_time = $("#pay_time").val(),
         status = '',
         status_arr = [],
         goods_status = '',
         goods_status_arr = [],
         store_id = '',
         store_id_arr = [];
       $("input[name=status]:checked").each(function() {
         status_arr.push($(this).val());
       });
       status = status_arr.join(',');
       $("input[name=goods_status]:checked").each(function() {
         goods_status_arr.push($(this).val());
       });
       goods_status = goods_status_arr.join(',');
       $("input[name=store_id]:checked").each(function() {
         store_id_arr.push($(this).val());
       });
       store_id = store_id_arr.join(',');
       table.reload('table_ids', {
         page: {
           curr: 1
         },
         where: {
           keywords: keywords,
           status: status,
           store_id: store_id,
           goods_status: goods_status,
           pay_time: pay_time
         }
       }, 'data');
     })
     // 获取选中项
     function getCheckValue() {
       var id_arr = [],
         id_str = '';
       var checkStatus = table.checkStatus('table_ids'),
         data = checkStatus.data;
       data.map(function(d) {
         id_arr.push(d.shipping_id);
       })
       id_str = id_arr.join(',');
       return id_str;
     }
   });
 </script>
 {/block}
